package com.test.jbpm.service.impl;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.jbpm.dao.ApproveDao;
import com.test.jbpm.dao.TroubleTicketDao;
import com.test.jbpm.domain.ApproveInfo;
import com.test.jbpm.service.ApproveService;


@Service
public class ApproveServiceImpl implements ApproveService {

	private ApproveDao approveDao;
	
	private TroubleTicketDao troubleTicketDao;
	
	@Autowired
	public void setApproveDao(ApproveDao approveDao) {
		this.approveDao = approveDao;
	}
	
	@Autowired
	public void setTroubleTicketDao(TroubleTicketDao troubleTicketDao) {
		this.troubleTicketDao = troubleTicketDao;
	}

	public void add(ApproveInfo approveInfo) {
		approveInfo.setApproveTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		approveDao.add(approveInfo);
		//流程继续向下走
		troubleTicketDao.completeTask(approveInfo.getTroubleTicket().getId(), approveInfo.getApprover().getId());
	}
	
	public void del(ApproveInfo approveInfo) {
		approveInfo.setApproveTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		approveDao.add(approveInfo);
		//流程继续向下走
		troubleTicketDao.completeBackTask(approveInfo.getTroubleTicket().getId(), approveInfo.getApprover().getId());
	}

	public List<ApproveInfo> findHistoryByTroubleTicketId(
			Integer troubleTicketId) {
		return approveDao.findHistoryByTroubleTicketId(troubleTicketId);
	}
}
